package com.spring.housing.redisConfig;


import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer;
import org.springframework.data.redis.serializer.StringRedisSerializer;
@Primary
@Configuration
//@ConditionalOnMissingBean(RedisTemplate.class)
public class RedisConfig {
    @Bean("redisTemplate")
    public RedisTemplate<String,Object> redisTemplate(RedisConnectionFactory factory){
        RedisTemplate redistemplate = new RedisTemplate();
        redistemplate.setConnectionFactory(factory);
        Jackson2JsonRedisSerializer Jackson2JsonRedisSerializer = new Jackson2JsonRedisSerializer(Object.class);
        //redistemplate.setDefaultSerializer(Jackson2JsonRedisSerializer);
        redistemplate.setKeySerializer(new StringRedisSerializer());
        redistemplate.setValueSerializer(Jackson2JsonRedisSerializer);
        return redistemplate;
    }

}

